<?php


class StudentController extends Controller
{
  private $_uid;

  public function init()
  {
    $this->checkUserLogin(1);
    $this->_uid = Yii::app()->user->id;
  }

  /**
   * 学生主页
   */
  public function actionIndex()
  {
    $this->render('index');
  }

  /**
   * 注销登录
   */
  public function actionLogout()
  {
    Yii::app()->user->logout();
    $this->redirect(Yii::app()->createUrl('site/index'));
  }

  /**
   * 文章列表
   * @param string $keywords 搜索关键字
   */
  public function actionArticle($keywords = '')
  {
    $data = LearnService::instance()->getList($this->_uid, $keywords);
    $this->render('article/list', array(
        'data' => $data,
    ));
  }


  /**
   * 学生做过的题库
   * @param string $keywords
   */
  public function actionQuestion_bank($keywords = '')
  {
    $data = QuestionBankService::instance()->getStudentQuestionBank($this->_uid, $keywords);
    $this->render('question/list', array(
        'data' => $data
    ));
  }

  /**
   * 学生的成绩
   * @param string $keywords
   */
  public function actionScore($keywords = '')
  {
    $data = QuestionBankService::instance()->getStudentQuestionBank($this->_uid, $keywords);
    $this->render('question/score', array(
        'data' => $data
    ));
  }

  /**
   * 我的提问
   * @param string $keywords
   */
  public function actionIssue($keywords = '')
  {
    $data = IssueService::instance()->getList(20,false,$this->_uid,$keywords);
    $this->render('issue/list', array(
        'data' => $data
    ));
  }
  /**
 * 我的回答
 */
  public function actionReply()
  {
    $data = IssueService::instance()->getUserReplyList($this->_uid,true);
    $this->render('reply/list', array(
        'data' => $data
    ));
  }

  /**
   * 我的主题
   * @param string $keywords
   */
  public function actionTopic($keywords = '')
  {
    $this->iCheck();
    $data = TopicService::instance()->getTopicList(20,false,$keywords,$this->_uid);
    $this->render('topic/list', array(
        'data' => $data
    ));
  }

  /**
   * 删除主题
   */
  public function actionDelete_topic()
  {
    echo TopicService::instance()->delete($this->filter($_POST['list']))?1:0;
  }

  /**
   * 我的回复
   * @param string $keywords
   */
  public function actionThread($keywords = '')
  {
    $this->iCheck();
    $data = TopicService::instance()->getUserThreads($this->_uid,20,$keywords);
    $this->render('thread/list', array(
        'data' => $data
    ));
  }

  /**
   * 删除回复
   */
  public function actionDelete_thread()
  {
    echo TopicService::instance()->deleteThread($this->filter($_POST['list']))?1:0;
  }
} 